package com.jeeplus.module.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jeeplus.common.pojo.Page;
import com.jeeplus.module.system.entity.Traceline;
import com.jeeplus.module.system.service.ITracelineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.jeeplus.common.pojo.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author housailei
 * @since 2019-05-23
 */
@RestController
@RequestMapping("/system/traceline")
public class TracelineController extends BaseController {
    @Autowired
    ITracelineService tracelineService;

    @GetMapping("test")
    public Object test() throws Exception {
        Page<Traceline> objectPage = new Page<>();
        objectPage.setSize(100);

        IPage<Traceline> page = tracelineService.pageConditions(objectPage);
        long current = page.getCurrent() + 1;
        long pages = page.getTotal()/100;
        for (long i=current;i<=pages;i++){
            tracelineService.pageConditions(new Page<>(i,100));
        }
        return true;
    }


    @GetMapping("traceline")
    public Object traceline() throws Exception {
        Page<Traceline> objectPage = new Page<>();
        objectPage.setSize(10);

        IPage<Traceline> page = tracelineService.pageTraceLineConditions(objectPage);
        long current = page.getCurrent() + 1;
        long pages = page.getTotal()/10;
        while (true){
            Page<Traceline> tracelinePage = tracelineService
                .pageTraceLineConditions(new Page<>(1, 10));
            if (!tracelinePage.hasNext()){
                break;
            }
        }
        return true;
    }

    @GetMapping("sampling")
    public Object sampling(@RequestParam(name = "bigthan") long bigthan,@RequestParam(name = "lessthan") long lessthan,@RequestParam(name = "samplingRate") int samplingRate) throws Exception {

        Page<Traceline> objectPage = new Page<>();
        objectPage.setSize(10);

        IPage<Traceline> page = tracelineService.pageTraceLineSampling(objectPage,samplingRate,lessthan,bigthan);
        long current = page.getCurrent() + 1;
        long pages = page.getTotal()/10;
        while (true){
            Page<Traceline> tracelinePage = tracelineService
                    .pageTraceLineSampling(new Page<>(1, 10),samplingRate,lessthan,bigthan);
            if (!tracelinePage.hasNext()){
                break;
            }
        }
        return true;
    }
}
